<?
require("config.php");

$label = "Order List";

$table="cus_order";


if ($action=="search"){

	$ftime=strtotime($fy.'-'.$fm.'-'.$fd.' 00:00:00');
	$ttime=strtotime($ty.'-'.$tm.'-'.$td.' 23:59:59');

	if ($no) $nostr=' and no = '.$no;
	else $nostr='';

	if ($firstname) $namestr="%$firstname%";
	else $namestr='';
	if ($lastname) 	$namestr.="$lastname%";
	if ($namestr) 	$namestr=" and member_name like '$namestr'";
	
	if ($member_email) $emailstr=" and member_email like '%$member_email%'";
	else $emailstr='';
	
	if ($hkid) $hkidstr=" and hkid like'%$hkid%'";
	else $hkidstr='';
	

	$Query="SELECT 
	id,
	no,
	trans_no,
	member_name,
	member_email,
	purchase_date,
	shipping_status,
	order_status,
	delivery_date
	 
	FROM $table WHERE 
	purchase_date	between $ftime and $ttime
	$nostr
	$namestr
	$emailstr
	$hkidstr
	ORDER BY id DESC";

	$r=myQuery($Query);

}else{

	$Query="SELECT 
	id,
	no,
	trans_no,
	member_name,
	member_email,
	purchase_date,
	shipping_status,
	order_status,
	delivery_date
	FROM $table ORDER BY id DESC";

	$r=myQuery($Query);

}

header("Content-type:application/vnd.ms-excel");  
header("Content-Disposition:filename=enquiry_" . date("Ymd") . ".xls");  



echo "Order No\t";  
echo "Transaction No\t";
echo "Customer Name\t";
echo "Customer Email\t"; 
echo "Order Date\t"; 
echo "Order Status\t";
echo "Shipping Status\t";
echo "Delivery Date\t\n";
for ($i=0;$i<count($r);$i++){

if ($r[$i][9]>strtotime('1980-01-01')) $date=date('Y-m-d',$r[$i][9]);
else $date='';

echo str_pad($r[$i][1],5,'0',STR_PAD_LEFT) . "\t"; 
echo $r[$i][2] . "\t"; 
echo $r[$i][3] . "\t"; 
echo $r[$i][4] . "\t"; 
echo $r[$i][5] . "\t"; 
echo date('Y-m-d H:i:s',$r[$i][6]) . "\t"; 
echo $r[$i][7] . "\t"; 
echo $r[$i][8] . "\t"; 
echo $date . "\t\n"; 
}

echo "\n"; 
}


?>

